package com.ghxxzx.daglcustom.listener;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.time.LocalDateTime;

// 开启定时任务
@Configuration
@EnableScheduling
public class SaticScheduleTask {

	@Primary
	@Bean
	public TaskExecutor primaryTaskExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		return executor;
	}

	// 添加定时任务
	// @Scheduled(cron = "0/5 * * * * ?")
	// 或直接指定时间间隔，例如：5分钟
	@Scheduled(fixedRate = 5 * 60 * 1000)
	private void myConfigureTasks() {
		System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
	}
}
